﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class BocLua_DB
    {
        public static DataTable SelectAll()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblCT_BocLua", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblCT_BocLua", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void Insert(BocLua newItem)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCTBocLua", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemCTBocLua", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_BocLua", newItem.MaCT_Boclua);
                command.Parameters.AddWithValue("@MaLo", newItem.Malo);
                command.Parameters.AddWithValue("@MaNX", newItem.MaNX);
                command.Parameters.AddWithValue("@MaTP", newItem.MaTP);
                command.Parameters.AddWithValue("@DienGiai", newItem.DienGiai);                
                command.Parameters.AddWithValue("@KL_HangVo", newItem.KL_hangvo);
                command.Parameters.AddWithValue("@KL_HangNguyen", newItem.KL_hangnguyen);
                command.Parameters.AddWithValue("@KL_HangBe", newItem.KL_hangbe);
                command.Parameters.AddWithValue("@XuatPL", newItem.XuatPL);
                command.Parameters.AddWithValue("@NgayThang", newItem.Ngaythang);
                
                command.ExecuteNonQuery();

            }
        }
        public static void Update(string oldMaCT_BocLua, BocLua newItem)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatCTBocLua", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatCTBocLua", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_BocLua", oldMaCT_BocLua);
                command.Parameters.AddWithValue("@MaLo", newItem.Malo);
                command.Parameters.AddWithValue("@MaNX", newItem.MaNX);
                command.Parameters.AddWithValue("@MaTP", newItem.MaTP);
                command.Parameters.AddWithValue("@DienGiai", newItem.DienGiai);
                command.Parameters.AddWithValue("@KL_HangVo", newItem.KL_hangvo);
                command.Parameters.AddWithValue("@KL_HangNguyen", newItem.KL_hangnguyen);
                command.Parameters.AddWithValue("@KL_HangBe", newItem.KL_hangbe);
                command.Parameters.AddWithValue("@XuatPL", newItem.XuatPL);
                command.Parameters.AddWithValue("@NgayThang", newItem.Ngaythang);
                command.ExecuteNonQuery();
            }
        }
        public static void Delete(string oldMaCT_BocLua)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCTBocLua", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaCTBocLua", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_BocLua", oldMaCT_BocLua);
                command.ExecuteNonQuery();

            }
        }
    }
}
